package com.bjpowernode.controller;

import com.bjpowernode.entity.TCustomerRemark;
import com.bjpowernode.query.CustomerRemarkQuery;
import com.bjpowernode.result.Result;
import com.bjpowernode.service.CustomerRemarkService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 客户备注控制器
 * 提供客户备注的添加、查询、更新、删除等操作
 */
@RestController
public class CustomerRemarkController {
    @Resource
    private CustomerRemarkService customerRemarkService;

    /**
     * 添加客户备注
     * @param customerRemarkQuery 客户备注信息
     * @return 操作结果
     */
    @PostMapping("/api/customer/remark")
    public Result addCustomerRemarkById(@RequestBody CustomerRemarkQuery customerRemarkQuery) {
        // 调用服务层方法添加客户备注
        int count = customerRemarkService.addCustomerRemarkById(customerRemarkQuery);
        // 根据添加结果返回相应的操作结果
        return count > 0 ? Result.OK() : Result.FAIL();
    }

    /**
     * 分页获取客户备注
     * @param id 客户ID
     * @param current 当前页码
     * @return 客户备注分页数据
     */
    @GetMapping("/api/customer/remark/{id}")
    // 接收请求体中的CustomerQuery对象作为参数，返回统一格式的Result响应
    public Result getActivities(@PathVariable Integer id, Integer current) {
        // 调用服务层方法分页获取客户备注
        PageInfo<TCustomerRemark> pageInfo = customerRemarkService.getCustomerRemarkByPage(id, current);
        // 返回分页结果
        return Result.OK(pageInfo);
    }

    /**
     * 根据ID获取客户备注详情
     * @param id 客户备注ID
     * @return 客户备注详情
     */
    @GetMapping("/api/customer/remark/detail/{id}")
    public Result getCustomerRemarkDetailById(@PathVariable Integer id) {
        // 调用服务层方法根据ID获取客户备注详情
        TCustomerRemark tCustomerRemark = customerRemarkService.getCustomerRemarkDetailById(id);
        // 返回客户备注详情
        return Result.OK(tCustomerRemark);
    }

    /**
     * 更新客户备注
     * @param customerRemarkQuery 客户备注信息
     * @return 操作结果
     */
    @PostMapping("/api/customer/remark/edit")
    public Result updateCustomerRemark(@RequestBody CustomerRemarkQuery customerRemarkQuery) {
        // 调用服务层方法更新客户备注
        int count = customerRemarkService.updateCustomerRemark(customerRemarkQuery);
        // 根据更新结果返回相应的操作结果
        return count > 0 ? Result.OK() : Result.FAIL();
    }

    /**
     * 根据ID删除客户备注
     * @param id 客户备注ID
     * @return 操作结果
     */
    @DeleteMapping("/api/customer/remark/delete/{id}")
    public Result deleteCustomerRemarkById(@PathVariable Integer id) {
        // 调用服务层方法根据ID删除客户备注
        int count = customerRemarkService.deleteCustomerRemarkById(id);
        // 根据删除结果返回相应的操作结果
        return count == 1 ? Result.OK(count) : Result.FAIL();
    }
}
